<?php 
	$logo = $this->Session->read('Client.logo');
	if(!empty($logo)){ 
		$logo = 'http://www.epicrisisweb.com/uploads/'.$logo;	
		$extension_logo = strtoupper(substr($logo,strrpos($logo, ".")+1));
	}


	
/* ----------------------------------------------------------------------- */

App::import('Vendor','xtcpdf');  
$tcpdf = new XTCPDF(); 
$textfont = 'dejavusans'; // looks better, finer, and more condensed than 'dejavusans' 

//print_r($evoluciones);

$tcpdf->SetAuthor("Epicrisis - http://www.epicrisisweb.com"); 
//$tcpdf->SetAutoPageBreak( false ); 
$tcpdf->SetAutoPageBreak(true, 20); 
//$tcpdf->SetTopMargin(20);
$tcpdf->setFontSubsetting(false);
// $tcpdf->setHeaderFont(array($textfont,'',13)); 
// $tcpdf->xheadercolor = array(255,255,255); 
// $tcpdf->xheadertext = 'Epicrisis - Receta'; 

// remove header
$tcpdf->setPrintHeader(false);

$tcpdf->xfootertext = nl2br($pie).'<br/>Fecha de Impresión: '.date("d/m/Y"); 

// Agrego la 1er Pagina
$tcpdf->AddPage('P', 'A4');
if(!empty($logo)){

	// set image scale factor
	$tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

	$tcpdf->Image($logo, 170, 5, '', '', $extension_logo, '', '', true, 150, '', false, false, 0, false, false, true);
}

// Now you position and print your page content 
$tcpdf->SetTextColor(0, 0, 0); 
$tcpdf->SetFont($textfont,'R',12); 

$fecha_nacimiento = date('d/m/Y', strtotime($person['Person']['fecha_nacimiento']));

$txt_paciente = "
	<p>".nl2br($encabezado)."</p>
	<p></p>

	<p>Rp./</p>
	<p>{$person['Person']['full_name']}</p>
	";

// print a block of text using Write()
$tcpdf->writeHTMLCell($w=0, $h=0, $x='', $y=20, $txt_paciente, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);


	$txt_registro = "<br><p><b>$TipoPrescripcion</b></p>";
	$tcpdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $txt_registro, 'B', $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);


/*
	$html_muro= '<table>';
	$tcpdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html_muro, '', $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
*/	

	foreach ($historial_completo as $key => $registro) {

		$html_muro= "<table><tr>
						<td>{$registro['fecha']}</td>
						<td>{$registro['item_name']}</td>";
		
			if(isset($registro['detalle'])){ $html_muro.="<td>{$registro['detalle']}</td>";	}	
		
		$html_muro.="	<td>{$registro['comentario']}</td>
					</tr></table>";
		$tcpdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html_muro, '', $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

	}

	// Muestro al PIE las firmas de todos los profesionales involucrados
	if( !empty($_SESSION['Auth']['User']['foto_firma']) ){ 
		$firma = '/uploads/'.$_SESSION['Auth']['User']['foto_firma'];	
		$html_firmas = "<br/><br/><br/><img src='$firma' height='70' hspace='20'>";
		$tcpdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html_firmas, '', $ln=1, $fill=0, $reseth=true, 'C', $autopadding=true);		
	}

	$html_muro= "<h1>Nro.Orden: $prescription_id</h1>";
	$tcpdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html_muro, '', $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);


/* ------------------------------------------------------------------------------ */

// reset pointer to the last page
$tcpdf->lastPage();
echo $tcpdf->Output('Epicrisis_Orden_'.$person['Person']['full_name'].'.pdf', 'D'); 
?>